package com.hoshiicloud.lessee.controller.category;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.auth.vo.TokenUsersVO;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.common.utils.token.UserInfoUtil;
import com.hoshiicloud.goods.entity.goods.GoodsSpecifications;
import com.hoshiicloud.goods.param.goods.*;
import com.hoshiicloud.goods.vo.GoodsSpecificationsValuesVo;
import com.hoshiicloud.lessee.feign.LesseeGoodsFeignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 2019/8/9 17:24 qry
 * */
@Slf4j
@Validated
@RestController
@RequestMapping("/category/goods-specifications")
@Api(value = "品类属性-规格管理", tags = {"品类属性-规格管理"})
public class LesseeGoodsSpecificationsController {
    private final LesseeGoodsFeignService goodsFeignService;
    public LesseeGoodsSpecificationsController(LesseeGoodsFeignService goodsFeignService) {
        this.goodsFeignService = goodsFeignService;
    }

    @ApiOperation(value = "分页查询商品属性")
    @PostMapping("/getPage")
    public Response<Page<GoodsSpecifications>> page(@RequestBody @Valid GoodsSpecificationsQueryParam param , HttpServletRequest rq) {
        param.setCompanyId(UserInfoUtil.getUserInfo(rq).getCompanyId());
        return goodsFeignService.getGoodsSpecPage(param);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增商品属性")
    public Response<Boolean> save(@RequestBody @Valid GoodsSpecificationsAddParam param, HttpServletRequest rq) {
        TokenUsersVO user = UserInfoUtil.getUserInfo(rq);
        param.setCompanyId(user.getCompanyId());
        param.setCreatedBy(user.getRealName());
        return goodsFeignService.saveGoodsSpec(param);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改商品属性")
    public Response update(@RequestBody @Valid GoodsSpecificationsUpdateParam param , HttpServletRequest rq) {
        param.setUpdatedBy(UserInfoUtil.getUserInfo(rq).getRealName());
        return goodsFeignService.updateGoodsSpec(param);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除商品属性")
    @ApiParam(name = "id", value = "主键ID", required = true)
    public Response<Boolean> delete(@PathVariable("id") Long id){
        return goodsFeignService.deleteGoodsSpec(id);
    }





    @ApiOperation(value = "分页查询商品规格_值")
    @PostMapping("/getSpecValuePage")
    public Response<Page<GoodsSpecificationsValuesVo>> getSpecValuePage(@RequestBody @Valid GoodsSpecificationsValuesQueryParam param) {
        return goodsFeignService.getGoodsSpecValuesPage(param);
    }

    @PostMapping("/saveSpecValue")
    @ApiOperation(value = "新增商品规格_值")
    public Response<Boolean> saveSpecValue(@RequestBody @Valid GoodsSpecificationsValuesAddParam param, HttpServletRequest rq) {
        param.setCreatedBy(UserInfoUtil.getUserInfo(rq).getRealName());
        return goodsFeignService.saveGoodsSpecValues(param);
    }

    @PutMapping("/updateSpecValue")
    @ApiOperation(value = "修改商品规格_值")
    public Response updateSpecValue(@RequestBody @Valid GoodsSpecificationsValuesUpdateParam param , HttpServletRequest rq) {
        param.setUpdatedBy(UserInfoUtil.getUserInfo(rq).getRealName());
        return goodsFeignService.updateGoodsSpecValues(param);
    }

    @DeleteMapping("/deleteSpecValue/{id}")
    @ApiOperation(value = "删除商品规格_值")
    @ApiParam(name = "id", value = "主键ID", required = true)
    public Response<Boolean> deleteSpecValue(@PathVariable("id") Long id){
        return goodsFeignService.deleteGoodsSpecValues(id);
    }

}
